<script>
export default {
  name: "humanModelExpressions",
  data() {
    return {
      dialogVisible: false,
      tableData: [],
      selectedList: [],
    }
  },
  methods: {
    openDialog(data, selectedData) {
      console.log(data, selectedData, '表情');
      this.dialogVisible = true
      this.tableData = data
      this.selectedList = selectedData
      this.$nextTick(() => {
        if (this.$refs.tableRef) {
          if (selectedData.length === 0) return false;
          this.$refs.tableRef.setCurrentRow(data.find(item => item.value === selectedData[0].value))
        }
      })

    },
    handleSelectionChange(val) {
      this.selectedList = [val]
    },
    submitData() {
      if (this.selectedList.length === 0 || this.selectedList.length > 1) {
        this.$message.error('请选择一个表情')
        return false
      }
      this.$emit('get-select', this.selectedList)
      this.dialogVisible = false
    }
  }
}
</script>

<template>
  <huilan-dialog
    title="设置表情"
    :visible.sync="dialogVisible"
    width="60%"
    append-to-body
  >
    <el-table
      :data="tableData"
      ref="tableRef"
      border
      width="100%"
      :header-cell-style="{background: '#fafafa'}"
      highlight-current-row
      @current-change="handleSelectionChange"
      style="width: 100%">

      <el-table-column
        prop="name"
        label="ID"
        #default="{row}"
      >
        <i v-if="selectedList.length>0 && selectedList[0].value === row.value" class="el-icon-success icon-select"></i>
        <i v-else class="el-icon-success" style="color: #ccc;"></i>
        {{row.value}}
      </el-table-column>
      <el-table-column
        prop="name"
        label="名称">
      </el-table-column>
    </el-table>
    <template #footer>
      <el-button @click="dialogVisible = false">取 消</el-button>
      <el-button type="primary" @click="submitData">确 定</el-button>
    </template>
  </huilan-dialog>
</template>

<style scoped lang="scss">
.icon-select {
  color: #00a680;
}
</style>
